package Factory;

import Observer.EnvironmentData;
import State.IdleState;
import State.MachineState;
import Strategy.OperationStrategy;

// 农机设备基类增强状态管理
public abstract class BaseAgriculturalMachine implements AgriculturalMachine {
    protected MachineState state;
    protected OperationStrategy currentStrategy;

    public BaseAgriculturalMachine() {
        this.state = new IdleState(this);
    }

    public void setState(MachineState state) {
        this.state = state;
    }

    @Override
    public void start() {
        state.start();
    }

    @Override
    public void stop() {
        state.stop();
    }

    // 其他方法...

    @Override
    public void update(EnvironmentData data) {
        // 由子类实现具体的环境条件判断
        determineStrategy(data);
        // 调用策略调整（子类无需重复编写）
        if (currentStrategy != null) {
            currentStrategy.adjust(this, data);
        }
    }

    // 子类实现策略判断逻辑（无类型硬编码）
    protected abstract void determineStrategy(EnvironmentData data);

    @Override
    public void setStrategy(OperationStrategy strategy) {
        this.currentStrategy = strategy;
    }
}
